/**
 * Created by Jan-Home on 2016/11/13 0013.
 */

const nodePath = require('path');
const webpack = require('webpack');
const packageInfo = require('./package.json');
const parsePackageName = nodePath.parse(packageInfo.name);
const phpDate = require('locutus/php/datetime/date');

const CustomNamePlugin = require('./misc/CustomVarLibraryNamePlugin');

const outputPath = __dirname + '/dist';

module.exports = {
	entry: './dist', // ./src 也是可以的
	output: {
		path: outputPath,
		filename: parsePackageName.name + '.js',
		library: parsePackageName.name,
		libraryTarget: 'umd',
	},
	resolve: {
		extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
	},
	externals: {
		'lodash': {
			root: '_',
			commonjs2: 'lodash',
			commonjs: 'lodash',
			amd: 'lodash',
			umd: '_'
		},
		'ke-url': {
			root: 'keUrl',
			commonjs2: 'ke-url',
			commonjs: 'ke-url',
			amd: 'ke-url',
			umd: 'keUrl'
		}
	},
	module: {
		loaders: [
			{
				test: /\.tsx?$/,
				loader: 'ts-loader'
			}
		]
	},
	// devtool: 'source-map',
	plugins: [
		new webpack.BannerPlugin(
			packageInfo.name + ' v' + packageInfo.version +
			', released under the MIT license' +
			', bundled at ' + phpDate('Y-m-d H:i:s', new Date()) +
			'.'
		),
		new CustomNamePlugin({
			'ke-url': 'keUrl'
		})
	]
};